//
//  Radio_Ting_CollectionViewCell.m
//  Time
//
//  Created by dllo on 16/7/23.
//  Copyright © 2016年 司昌宝. All rights reserved.
//

#import "Radio_Ting_CollectionViewCell.h"

@interface Radio_Ting_CollectionViewCell ()
/**
 *  图
 */
@property (nonatomic,retain) UIImageView *tingImageView;
/**
 *  文字
 */
@property (nonatomic,retain) UILabel *titleLabel;
/**
 *  作者名
 */
@property (nonatomic,retain) UILabel *authorNameLabel;
/**
 *  按钮
 */
@property (nonatomic,retain) UIImageView *playButtonImage;

@end

@implementation Radio_Ting_CollectionViewCell

-(void)dealloc{
    [_tingImageView release];
    [_titleLabel release];
    [_authorNameLabel release];
    [_model release];
    [super dealloc];
}

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.tingImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.tingImageView];
        [_tingImageView release];
        
        self.titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.titleLabel];
        [_titleLabel release];
        
        self.authorNameLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.authorNameLabel];
        [_authorNameLabel release];
        
        self.playButtonImage = [[UIImageView alloc] init];
        [self.tingImageView addSubview:self.playButtonImage];
        [_playButtonImage release];
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    [self.tingImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(0);
        make.right.equalTo(self.contentView.mas_right).offset(0);
        make.top.equalTo(self.contentView.mas_top).offset(0);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-50);
    }];
    
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.font = [UIFont systemFontOfSize:12.0];
    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(0);
        make.right.equalTo(self.contentView.mas_right).offset(0);
        make.top.equalTo(self.tingImageView.mas_bottom).offset(0);
        make.bottom.equalTo(self.tingImageView.mas_bottom).offset(40);
    }];
    
    self.authorNameLabel.textAlignment = NSTextAlignmentCenter;
    self.authorNameLabel.textColor = [UIColor grayColor];
    self.authorNameLabel.font = [UIFont systemFontOfSize:10.0];
    [self.authorNameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(0);
        make.right.equalTo(self.contentView.mas_right).offset(0);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(-10);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(0);
    }];
    
    [self.playButtonImage mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.tingImageView.mas_right).offset(-5);
        make.bottom.equalTo(self.tingImageView.mas_bottom).offset(-5);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(30);
    }];
    
}

-(void)setModel:(TingModel *)model{
    if (_model != model){
        [_model release];
        _model = [model retain];
    }
    [self.tingImageView setImageWithURL:[NSURL URLWithString:model.imgUrl] placeholderImage:nil];
    self.titleLabel.text = model.title;
    self.authorNameLabel.text = model.scbUserinfo.uname;
    self.playButtonImage.image = [UIImage imageNamed:@"播放 (1).png"];
}


@end
